package com.aramis.mydytt.ui.base

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import java.io.Serializable

/**
 * Description: BaseRecyclerAdapter
 * @author lizhidan
 * Created: 2021/5/24
 */
abstract class BaseRecyclerAdapter<M : Serializable, T : RecyclerView.ViewHolder> : RecyclerView.Adapter<T>() {
    protected val dataList = mutableListOf<M>()

    override fun onBindViewHolder(holder: T, position: Int) {
        onBind(holder, dataList[position], position)
    }

    abstract fun onBind(holder: T, data: M, position: Int)

    override fun getItemCount(): Int = dataList.size

    protected fun createView(parent: ViewGroup, id: Int): View {
        return LayoutInflater.from(parent.context).inflate(id, parent, false)
    }
}